#!usr/bin/env python3
import os

#默认情况下twisted是select()模式在win下面只支持512个客户端链接,linux最多支持1024
#下面判断在不同系统开启iocpreactor或者epollreactor模式

if os.name!='nt': #linux系统
    from twisted.internet import epollreactor
    epollreactor.install()    
else:
    from twisted.internet import iocpreactor
    iocpreactor.install()

from twisted.internet.protocol import Factory,Protocol
from twisted.internet import reactor
import socket

class GameSocket(Protocol):
    def connectionMade(self): #重新父类的函数
        print("New user")
        
        
    def connectionLost(self,reeason):#重新父类的函数
        print("Lost Client .. ",str(reeason))
    
    def dataReceived(self,data):#重新父类的函数
        print("Get data ",str(data))

      
if __name__ == "__main__":
    f = Factory()
    f.protocol = GameSocket
    reactor.listenTCP(5200,f)
    print("server start ..")
    reactor.run()